package com.example.dormitorysystem.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.dormitorysystem.entity.Buildings;
import com.example.dormitorysystem.mapper.BuildingsMapper;
import com.example.dormitorysystem.service.BuildingsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.dormitorysystem.utils.RedisUtil;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 吉吉王国组
 * @since 2022-11-26
 */
@Service
public class BuildingsServiceImpl extends ServiceImpl<BuildingsMapper, Buildings> implements BuildingsService {

    private RedisUtil redisUtil;


    //这里实现具体的寝室楼信息
    @Override
    public Buildings getBuildingInfoById(Integer id, HttpServletRequest request) {
        //传入的就是这个id
        Buildings buildings = baseMapper.selectById(id);
        if(buildings.getIsValid() == 0 || buildings.getIsDel() == 1) return null;

        //这里传回去的object就是目标building，只需要提取内容输出就行
        return buildings;
    }

    //这里实现寝室楼列表的输出

    //这里实现getList
    @Override
    public List<Buildings> getBuildingList() {
        //直接返回这个表
        QueryWrapper<Buildings> buildingsQueryWrapper = new QueryWrapper<>();
        buildingsQueryWrapper.eq("is_del",0).eq("is_valid",1);
        return baseMapper.selectList(buildingsQueryWrapper);
    }
}
